// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

/// 云函数入口函数
exports.main = async (event, context) => {
  if (event.action == 'add') {
    return await cloud.database().collection('collect').add({
      data:{
        doctorId:event.doctorId,
        doctorName:event.doctorName,
        patientAdmin:event.patientAdmin,
        patientName:event.patientName,
        collectTime:event.collectTime,
        // isCollect:event.isCollect,
      }
    }).then(res => {
      return res
    }).catch(res => {
      return res
    })
  } 
  else if(event.action=="findOne"){
    return await cloud.database().collection('collect').where({
      doctorId:event.doctorId,
      patientAdmin:event.patientAdmin,
    }).get()
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
  else if(event.action=="findPatient"){
    return await cloud.database().collection('collect').where({
      patientAdmin:event.patientAdmin,
    }).get()
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
  else if(event.action=="findDoctor"){
    return await cloud.database().collection('collect').where({
      doctorId:event.doctorId,
    }).get()
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
  else if(event.action=="del"){
    return await cloud.database().collection('collect').where({
      doctorId:event.doctorId,
      patientAdmin:event.patientAdmin,
    }).remove()
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
}

